﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using Utility.Math;

namespace Utility.Inspector.ReorderableList
{
	public static class ListDrawer
	{
		//int
		public static void DrawIntList (IList<int> list, ReorderableListFlags flags = default)
		{
			ReorderableListGUI.ListField (list, EditorGUI.IntField, flags);
		}
		//float
		public static void DrawFloatList (IList<float> list, ReorderableListFlags flags = default)
		{
			ReorderableListGUI.ListField (list, EditorGUI.FloatField, flags);
		}
		//bool
		public static void DrawBoolList (IList<bool> list, ReorderableListFlags flags = default)
		{
			ReorderableListGUI.ListField (list, EditorGUI.Toggle, flags);
		}
		//vec2
		public static void DrawVector2List (IList<Vector2> list, ReorderableListFlags flags = default)
		{
			ReorderableListGUI.ListField (list, DrawVector2Item, flags);
		}
		//vec2int
		public static void DrawVector2IntList (IList<Vector2Int> list, ReorderableListFlags flags = default)
		{
			ReorderableListGUI.ListField (list, DrawVector2IntItem, flags);
		}
		//vec3
		public static void DrawVector3List (IList<Vector3> list, ReorderableListFlags flags = default)
		{
			ReorderableListGUI.ListField (list, DrawVector3Item, flags);
		}
		//vec3int
		public static void DrawVector3IntList (IList<Vector3Int> list, ReorderableListFlags flags = default)
		{
			ReorderableListGUI.ListField (list, DrawVector3IntItem, flags);
		}
		//vec4
		public static void DrawVector4List (IList<Vector4> list, ReorderableListFlags flags = default)
		{
			ReorderableListGUI.ListField (list, DrawVector4Item, flags);
		}

		//string
		public static void DrawStringList (IList<string> list, ReorderableListFlags flags = default)
		{
			ReorderableListGUI.ListField (list, EditorGUI.TextField, flags);
		}




		//object
		public static void DrawObjectList<T> (IList<T> list, bool allowSceneObject, ReorderableListFlags flags = default)
			where T : UnityEngine.Object
		{
			if (allowSceneObject)
			{
				ReorderableListGUI.ListField (list, DrawObjectItem_AllowSceneObject, flags);
			}
			else
			{
				ReorderableListGUI.ListField (list, DrawObjectItem_DisallowSceneObject, flags);
			}
		}

		#region helper
		//vector2
		static Vector2 DrawVector2Item (Rect pos, Vector2 item)
		{
			return EditorGUI.Vector2Field (pos, GUIContent.none, item);
		}
		static Vector2Int DrawVector2IntItem (Rect pos, Vector2Int item)
		{
			return EditorGUI.Vector2IntField (pos, GUIContent.none, item);
		}
		//vector3
		static Vector3 DrawVector3Item (Rect pos, Vector3 item)
		{
			return EditorGUI.Vector3Field (pos, GUIContent.none, item);
		}
		static Vector3Int DrawVector3IntItem (Rect pos, Vector3Int item)
		{
			return EditorGUI.Vector3IntField (pos, GUIContent.none, item);
		}
		//vector4
		static Vector4 DrawVector4Item (Rect pos, Vector4 item)
		{
			return EditorGUI.Vector4Field (pos, GUIContent.none, item);
		}


		//object
		static T DrawObjectItem_AllowSceneObject<T> (Rect pos, T obj)
			where T : UnityEngine.Object
		{
			return (T)EditorGUI.ObjectField (pos.ShrinkHeight (2), obj, typeof (T), true);
		}

		static T DrawObjectItem_DisallowSceneObject<T> (Rect pos, T obj)
			where T : UnityEngine.Object
		{
			return (T)EditorGUI.ObjectField (pos.ShrinkHeight (2), obj, typeof (T), false);
		}
		#endregion
	}
}